package com.gotobject.junit.internal.runners.model;

/**
 *
 * @author Huascar A. Sanchez (huascar.sanchez@gmail.com)
 */
public final class Explosion {
	private final int           users;
	private final int           iterations;
	private final long          responseTime;
    private final StringBuilder testType;


    /**
	 * Construct a {@code Configuration} to be used to exercise a
     * performance test.
     *
	 * @param users # of threads
	 * @param iterations # of times each thread will be run.
	 * @param responseTime time between executions.
	 */
	public Explosion(int users, int iterations, long responseTime){
		this.users 			= users;
		this.iterations 	= iterations;
		this.responseTime 	= responseTime;
        testType            = new StringBuilder();
    }

    public Explosion(int users, int iterations){
        this(users, iterations, 0L);    //0L means no needed.
    }

    public Explosion forTest(String type){
        checkAvailability();
        testType.append(type);
        return this;
    }

    private void checkAvailability(){
        if(testType.length() > 0){
            throw new IllegalStateException("unable to accept more tests.");
        }
    }


    /**
	 *
	 * @return # of threads.
	 */
	public int getUsers() {
		return users;
	}


	/**
	 *
	 * @return # of times each thread will be run.
	 */
	public int getIterations() {
		return iterations;
	}


	/**
	 * 
	 * @return time between executions.
	 */
	public long getResponseTime() {
		return responseTime;
	}

    /**
     * @return test type to be exercise
     */
    public String getTestType() {
        return testType.toString();
    }

    @Override
    public String toString() {
        return new StringBuilder("Explosion consisting of [")
                .append("user=")
                .append(getUsers())
                .append(", iterations=")
                .append(getIterations()).append(", response time=")
                .append(getResponseTime()).append(", test type=")
                .append(getTestType())
        .toString();
    }
}
